<?php
class tixianControl extends skymvc{
	public $sw=" 1 ";
 	private $admin;
	public function __construct(){
		parent::__construct();	
		$this->admin=M("login")->getAdmin(); 
	
	}
	
	public function onDefault(){
		$limit=20;
		$where= $this->sw;
		$url=APPADMIN."?m=tixian";
		$start=get('per_page','i');
		$option=array(
			"start"=>$start,
			"limit"=>$limit,
			"order"=>"id DESC",
			"where"=>$where,
		);
		$rscount=true;
		$data=M("tixian")->select($option,$rscount);
		$pagelist=$this->pagelist($rscount,$limit,$url);
		 
		$this->smarty->assign(array(
			"data"=>$data,
		 
		));
		$this->smarty->display("tixian/index.html");
	}
	
	
	public function onShow(){
		$id=get('id','i');
		$data=M("tixian")->selectRow("id=".$id); 
		$this->smarty->assign(array(
			"data"=>$data
		));
		$this->smarty->display("tixian/show.html");
	}
	
	/**
	*订单确认
	*/
	public function onConfirm(){
		$id=get_post('id','i');
		$data=M("tixian")->selectRow(array("where"=>"id=".$id));
		if(empty($data)) $this->goall("参数出错",1);
		M("tixian")->update(array("status"=>1),"id=".$id);
		$content=post('content');
		M('tixian_log')->insert(array(
			"dateline"=>time(),
			"admin_id"=>$this->admin['id'],
			"order_id"=>$id,
			"content"=>$content,
		));
		 
		$this->goall("确认成功");
	}
	 
	/**
	*订单发送
	*/
	public function onSend(){
		$id=get_post('id','i');
		$data=M("tixian")->selectRow(array("where"=>"id=".$id));
		if(empty($data)) $this->goall("参数出错",1);
		if($data['status']<2){
			M("tixian")->update(array("status"=>2),"id=".$id);
		}
		$content=post('content');
		M('tixian_log')->insert(array(
			"dateline"=>time(),
			"admin_id"=>$this->admin['id'],
			"order_id"=>$id,
			"content"=>$content,
		));
		$this->goall("支付成功");
	}
	
	/**
	*订单完成
	*/
	public function onFinish(){
		$id=get_post('id','i');
		$data=M("tixian")->selectRow(array("where"=>"id=".$id));
		if(empty($data)) $this->goall("参数出错",1);
		M("tixian")->update(array("status"=>3),"id=".$id);
		$content=post('content');
		M('tixian_log')->insert(array(
			"dateline"=>time(),
			"admin_id"=>$this->admin['id'],
			"order_id"=>$id,
			"content"=>$content,
		));
		
		$this->goall("订单完成");
	}
	
	/**
	*取消订单
	*/
	 	
	public function onCancel(){
		$id=get_post('id','i');
		$data=M("tixian")->selectRow(array("where"=>"id=".$id));
		if(empty($data)) $this->goall("参数出错",1);
		if($data['status']>=3) $this->goall("操作失败",1);
		M("tixian")->update(array("status"=>10),"id=".$id);
		$content=post('content');
		$message=post('message','h');
		M('tixian_log')->insert(array(
			"dateline"=>time(),
			"admin_id"=>$this->admin['id'],
			"order_id"=>$id,
			"content"=>$content."，原因：".$message,
		));
		
		$this->goall("取消成功");
	}

	public function onDelete(){
		$id=get_post('id','i');
		$data=M("tixian")->selectRow(array("where"=>"id=".$id));
		if(empty($data)) $this->goall("参数出错",1);
		if($data['status']!=0 && $data['status']!=10 ) $this->goall("操作失败",1);
		M("tixian")->update(array("status"=>99),"id=".$id);
		$content=post('content');
		$message=post('message','h');
		M('tixian_log')->insert(array(
			"dateline"=>time(),
			"admin_id"=>$this->admin['id'],
			"order_id"=>$id,
			"content"=>$content."，原因：".$message,
		));
		$this->goall("订单删除");
	}	
	
	 
}

?>